package jxerializeml;

import jxerializeml.clues.classes.InvokeClassListeners;
import jxerializeml.clues.fields.AllowedValuesRange;
import jxerializeml.clues.fields.InvokeSetter;
import jxerializeml.clues.fields.RewriteField;
import jxerializeml.clues.fields.SetComment;
import jxerializeml.clues.structures.ClassListener;
import jxerializeml.errors.input.XMLReaderError;
import jxerializeml.xml.transformers.DefaultTransformers;

@SuppressWarnings("unused")
class Simple {
	private boolean shitLoadOfNothing = false;
	
	public Simple(boolean val) {
		this.shitLoadOfNothing = val;
	}
	
	public Simple() {
		//
	}
}	

@SuppressWarnings("unused")
class Foo {
	private boolean ctrl = false;
	private double abc = 1.123;
	public Simple simple = new Simple();
	private float pi = 3.141f;
	protected String greeting = "Hello, world";
}

@SuppressWarnings("unused")
class A {
	private int valA = 1;
	private int valB = 2;
	private int valC = 3;
}

enum Testnum {
	ALPHA,
	BETA,
	GAMA,
	DELTA;
}

@InvokeClassListeners(
	methods = {
		ClassListener.PRE_SERIALIZE,
		ClassListener.POST_SERIALIZE,
		ClassListener.PRE_DESERIALIZE,
		ClassListener.POST_DESERIALIZE
	}
)
@SuppressWarnings("unused")
public class Test {
	@InvokeSetter()
	@AllowedValuesRange(min = 100, max = 1000)
	private int number = 101;
	
	@SetComment(description = "Set to true if you want")
	private boolean ctrl = false;
	
	private Foo foo = new Foo();
	private int[] constants = new int[]{11, 22, 33, 44, 55};
	private Simple[] simple = new Simple[]{new Simple(false), new Simple(false), new Simple(false)};
	private Testnum[] testnum = {Testnum.ALPHA, Testnum.BETA, Testnum.GAMA};
	
	@RewriteField(fieldName = "rewritedName", classType = long.class)
	private int originalName = -8;
	
	private void preserialize()     { System.out.println("#preSerialize"); }
	private void postserialize()    { System.out.println("#postSerialize"); }
	private void predeserialize()   { System.out.println("#preDeserialize"); }
	private void postdeserialize()  { System.out.println("#postDeserialize"); }
	
	public void setNumber(int number) {
		this.number = number;
	}
	
	public static void main(String[] args) throws Exception {
		new JXerializeML<Test>().writeObject(new Test(), "res/test.xml", DefaultTransformers.TECHNICAL);
		
		Test test = new JXerializeML<Test>().readObject("res/test.xml", DefaultTransformers.TECHNICAL);
		System.out.println(new JXerializeML<Test>().serialize(test, DefaultTransformers.TECHNICAL));
	}
}
